package com.wyix.util;

import com.wyix.entity.SmartPhone;

/**
 * @author wangdx
 * @since 2025/8/1
 */
public class PhoneFactory {
    // 唯一工厂实例
    private static final PhoneFactory INSTANCE = new PhoneFactory();

    // 私有构造：仅内部可创建
    private PhoneFactory() {
        System.out.println("手机工厂初始化完成，准备生产...");
    }

    // 全局访问点
    public static PhoneFactory getInstance() {
        return INSTANCE;
    }

    // 生产手机（调用SmartPhone构造方法）
    public SmartPhone producePhone(String productId, String brand, String model, double price) {
        if (!PhoneValidator.isValidModel(model)) {
            throw new IllegalArgumentException("型号不能为空！");
        }
        if (!PhoneValidator.isValidPrice(price)) {
            throw new IllegalArgumentException("价格必须大于0！");
        }
        return new SmartPhone(productId, brand, model, price);
    }
}